# Contibutor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=qt5-translations
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.15.10
pkgrel=1
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
pkgdesc="A cross-platform application and UI framework (Translations) (mingw-w64)"
url='https://www.qt.io/'
license=('GPL3' 'LGPL' 'FDL' 'custom')
depends=("${MINGW_PACKAGE_PREFIX}-qt5-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")
groups=("${MINGW_PACKAGE_PREFIX}-qt5")
options=('!strip')
_pkgfn="${_realname/5-/}-everywhere-opensource-src-${pkgver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/$pkgver/submodules/$_pkgfn.tar.xz")
sha256sums=('38b942bc7e62794dd072945c8a92bb9dfffed24070aea300327a3bb42f855609')

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  qmake ../${_pkgfn/opensource-/}

  make
}

check() {
  cd build-${MSYSTEM}
  make check -j1 -k
}

package() {
  cd build-${MSYSTEM}

  # Fix Makefiles
  local PREFIX_WIN=$(cygpath -am ${MINGW_PREFIX})
  find "${srcdir}/build-${MSYSTEM}" -type f \( -name 'Makefile*' \) \
      -exec sed -i -e "s|${PREFIX_WIN:0:2}\$(INSTALL_ROOT|\$(INSTALL_ROOT|g" {} \;
  find "${srcdir}/build-${MSYSTEM}" -type f \( -name 'Makefile*' \) \
      -exec sed -i -e "s|)${PREFIX_WIN:2}|)${MINGW_PREFIX}|g" {} \;

  make INSTALL_ROOT="${pkgdir}" install

  install -d "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $srcdir/${_pkgfn/opensource-/}/LICENSE* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
